import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hansheng.dao.SemiProductDao;
import com.hansheng.entity.VSemiproductEntity;

import java.util.List;
import java.util.TreeSet;

/**
 * Created by GoldenMan on 2017/5/29.
 */
public class testSemiProductDao extends SpringTestCase {
    private SemiProductDao semiProductDao;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        semiProductDao = (SemiProductDao) getFactory().getBean("semiProductDao");
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testSemiProductDao() {
        // Created by GoldenMan at 2017/6/3    TODO:获取 outForm的半成品semiProduct
        List spList=semiProductDao.getSemiProductListByOutFormNo("123");
        JSONArray jsonArray=new JSONArray();
        TreeSet set=new TreeSet();
        for (int i = 0; i < spList.size(); i++) {
            JSONObject tempObject=new JSONObject();
            VSemiproductEntity semiproductEntity=(VSemiproductEntity)spList.get(i);
            tempObject.put("outFormNo",semiproductEntity.getOutFormNo());
            tempObject.put("outId",semiproductEntity.getOutId());
            tempObject.put("sid",semiproductEntity.getSid());
            tempObject.put("spid",semiproductEntity.getSpid());
            tempObject.put("length",semiproductEntity.getLength());
            tempObject.put("width",semiproductEntity.getWidth());
            tempObject.put("height",semiproductEntity.getHeight());
            tempObject.put("count",semiproductEntity.getCount());
            tempObject.put("weightThe",semiproductEntity.getWeightThe());
            tempObject.put("weightAct",semiproductEntity.getWeightAct());
            tempObject.put("finishedTime",semiproductEntity.getFinishedTime());
            tempObject.put("name",semiproductEntity.getName());
            tempObject.put("position",semiproductEntity.getPosition());
            jsonArray.add(tempObject);
            set.add(semiproductEntity.getSid());
        }
        jsonArray.add(set.toArray());
        System.out.println(jsonArray.toString());
//        // Created by GoldenMan at 2017/6/3    TODO:saveSemiProductDetail
//        boolean flag=true;
//        String spD="[{\"operator\":1,\"length\":1,\"width\":1,\"height\":1,\"count\":1,\"weightThe\":0.00000785,\"weightAct\":0,\"sid\":2},{\"operator\":1,\"length\":1,\"width\":1,\"height\":1,\"count\":1,\"weightThe\":0.00000785,\"weightAct\":0,\"sid\":20},{\"operator\":1,\"length\":1,\"width\":1,\"height\":1,\"count\":1,\"weightThe\":0.00000785,\"weightAct\":0,\"sid\":26}]";
//        JSONArray semiProductDetails=JSONArray.parseArray(spD);
//        for (int i = 0; i < semiProductDetails.size(); i++) {
//            JSONObject detail=(JSONObject)semiProductDetails.get(i);
//            SemiProductEntity semiProductEntity=new SemiProductEntity();
//            semiProductEntity.setOutId(4);
//            semiProductEntity.setSid(Integer.parseInt(detail.get("sid").toString()));
//            semiProductEntity.setOperator(1);
//            semiProductEntity.setLength(Integer.parseInt(detail.get("length").toString()));
//            semiProductEntity.setWidth(Integer.parseInt(detail.get("width").toString()));
//            semiProductEntity.setHeight(Integer.parseInt(detail.get("height").toString()));
//            semiProductEntity.setCount(Integer.parseInt(detail.get("count").toString()));
//            semiProductEntity.setWeightThe(Double.parseDouble(detail.get("weightThe").toString()));
//            semiProductEntity.setWeightAct(Double.parseDouble(detail.get("weightAct").toString()));
//            semiProductEntity.setStatus(0);
//            flag&=semiProductDao.saveSemiProduct(semiProductEntity);
//        }
//        if(flag)
//            System.out.println("ok");
//        else
//            System.out.println("not ok");
    }
}